package com.kolalo.annotation.beans.service;

import com.kolalo.annotation.Interface.IBeansInterface;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Primary;

public class ServiceBeanTest implements IBeansInterface {
    @Primary
    public void Test() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.scan(ServiceBean.class.getPackage().getName());
        context.refresh();
        ServiceBean ms = context.getBean(ServiceBean.class);
        ServiceBean ms1 = context.getBean("ms", ServiceBean.class);////通过Service注解获得bean
        System.out.println(ms.add(1, 2));
        System.out.println(ms.subtract(2, 1));

        System.out.println(ms1.add(2, 4));
        System.out.println(ms1.subtract(2, 4));

        //close the spring context
        context.close();
    }

}
